﻿/****************************************************************
 * Copyright (c) 2010-2013 Besture All Rights Reserved.
 * 
 * File Name:		ShortContentDac 
 * 
 * Created:		2013-9-3 21:16:43
 * Original Author:	nitao 
 * 
 * ------------------------------------------------------------
 * MODIFICATION HISTORY
 * ------------------------------------------------------------
 * When			Who		Why
 * ------------------------------------------------------------
 * 
 *
 ****************************************************************/

using System;
using Besture.Common;
using Besture.Dal;
using Besture.Model;

namespace Besture.Bll
{
    public class ShortContentDac : BaseFacade
    {
        private ShortContentDal ShortContentDal = new ShortContentDal();
        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="entryKey"></param>
        /// <returns></returns>
        public ShortContentModel GetContent(string entryKey)
        {
            try
            {
                CreateConnection();
                ShortContentModel model = ShortContentDal.GetContent(entryKey);
                if (model == null)
                {
                    model = new ShortContentModel();
                    model.EntryKey = entryKey;
                    ShortContentDal.Add(model);
                }
                return model;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }

        /// <summary>
        /// 设置值
        /// </summary>
        /// <param name="entryKey"></param>
        /// <param name="entryValue"></param>
        /// <returns></returns>
        public int SetContent(string entryKey, string entryValue)
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                int lsRecord = 0;
                var model = ShortContentDal.GetContent(entryKey);
                model.EntryValue = entryValue;
                model.EntryTitle = ""; 
                lsRecord = ShortContentDal.Update(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }
    }
}
